/*
 * Catalogue.java
 *
 * Created on 27 March 2007, 11:57
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usyd.comp5348;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;

/**
 * Entity class Catalogue
 * 
 * @author Yuezhong Zhang
 */
@Entity(name="Catalogue")
@NamedQueries(
{ 
   @NamedQuery(
     name="getVideoByCatalogueNumber",
     query="SELECT c FROM Catalogue c WHERE c.catalogueNumber = :catalogueNumber"
   ), 
   @NamedQuery(
     name="getVideosByDirector",
     query="SELECT c FROM Catalogue c WHERE c.director = :director"
   ),
   @NamedQuery(
     name="getVideosByGenre",
     query="SELECT c FROM Catalogue c WHERE c.genre = :genre"
   )
 }
)
public class Catalogue implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO, generator="CatIdSeq")
    @SequenceGenerator(name="CatIdSeq", sequenceName="cat_id_seq")
    private Integer id;
    
    /** Creates a new instance of Catalogue */
    public Catalogue() {
    }
    
    /** Constructor from a basic POJO class */
    public Catalogue(CatalogueInfo c) {
        setCatalogueNumber(c.getCatNo());
        setDirector(c.getDirector());
        setGenre(c.getGenre());
        if (c.getId() != CatalogueInfo.UNDEFINED)
            setId(c.getId());
        setPrice(c.getPrice());
        setTitle(c.getTitle());
    }
    
    public CatalogueInfo getCatalogueInfo() {
        CatalogueInfo c = new CatalogueInfo(this.getId(), this.getCatalogueNumber(), this.getTitle(), this.getDirector(), this.getGenre(), this.getPrice());
        return c;
    }

    /**
     * Gets the id of this Catalogue.
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }

    /**
     * Sets the id of this Catalogue to the specified value.
     * @param id the new id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Catalogue.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Catalogue object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Catalogue)) {
            return false;
        }
        Catalogue other = (Catalogue)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "usyd.comp5348.entity.Catalogue[id=" + id + "]";
    }

    /**
     * Holds value of property catalogueNumber.
     */
    @Column(name="catalogueNumber",length=50,nullable=false)
    private String catalogueNumber;

    /**
     * Getter for property catalogueNumber.
     * @return Value of property catalogueNumber.
     */
    public String getCatalogueNumber() {
        return this.catalogueNumber;
    }

    /**
     * Setter for property catalogueNumber.
     * @param catalogueNumber New value of property catalogueNumber.
     */
    public void setCatalogueNumber(String catalogueNumber) {
        this.catalogueNumber = catalogueNumber;
    }

    /**
     * Holds value of property title.
     */
    @Column(name="title", length=100, nullable=false)
    private String title;

    /**
     * Getter for property title.
     * @return Value of property title.
     */
    public String getTitle() {
        return this.title;
    }

    /**
     * Setter for property title.
     * @param title New value of property title.
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * Holds value of property director.
     */
    @Column(name="director", length=50,nullable=false)
    private String director;

    /**
     * Getter for property director.
     * @return Value of property director.
     */
    public String getDirector() {
        return this.director;
    }

    /**
     * Setter for property director.
     * @param director New value of property director.
     */
    public void setDirector(String director) {
        this.director = director;
    }

    /**
     * Holds value of property genre.
     */
    @Column(name="genre", length=20, nullable=false)
    private String genre;

    /**
     * Getter for property genre.
     * @return Value of property genre.
     */
    public String getGenre() {
        return this.genre;
    }

    /**
     * Setter for property genre.
     * @param genre New value of property genre.
     */
    public void setGenre(String genre) {
        this.genre = genre;
    }

    /**
     * Holds value of property price.
     */
    @Column(name="price",nullable=false)
    private float price;

    /**
     * Getter for property price.
     * @return Value of property price.
     */
    public float getPrice() {
        return this.price;
    }

    /**
     * Setter for property price.
     * @param price New value of property price.
     */
    public void setPrice(float price) {
        this.price = price;
    }
    
}
